<template>
  <div id="FunctionModule">
    <vxe-toolbar perfect>
      <template #buttons>
        <div class="smallToolTitle">交接单明细</div>
        <vxe-button type="text" class="button-blue" icon="vxe-icon-refresh" content="刷新" :loading="showLoading" @click="handleSearch"></vxe-button>
        <vxe-button type="text" class="button-blue" icon="vxe-icon-print" content="打印" :loading="showLoading" @click="quietPrint"></vxe-button>
      </template>
    </vxe-toolbar>

    <div class="modulTable">
      <vxe-table ref="unqualifiedTable" border="inner" height="auto" class="mytable-scrollbar" :loading="showLoading" :data="reqMainList" @current-change="moduleRowClick" :row-config="{ isCurrent: true, isHover: true }" :keyboard-config="{
          isArrow: true,
          isTab: true,
          isEdit: true
        }" :edit-config="{
          trigger: 'click',
          mode: 'cell',
          showIcon: false,
          showStatus: true
        }" :edit-rules="formRule" resizable show-overflow keep-source>
        <vxe-column type="checkbox" width="50" align="center"></vxe-column>
        <vxe-column type="seq" title="序号" width="30" align="center"></vxe-column>
        <!-- <vxe-column field="reqNo" title="条码号" :edit-render="{ autofocus: '.vxe-input--inner' }" align="center"> </vxe-column>
        <vxe-column field="patNa" title="病人姓名" width="120" align="center"> </vxe-column>
        <vxe-column field="age" title="病人年龄" align="center"> </vxe-column>
        <vxe-column field="sex" title="证件号码" align="center"> </vxe-column>
        <vxe-column field="diagnose" title="临床诊断" align="center"> </vxe-column>
        <vxe-column field="bedNo" title="床号" align="center"> </vxe-column>
        <vxe-column field="reqDeptNa" title="申请科室名称" align="center"> </vxe-column>
        <vxe-column field="reqDoctorNa" title="申请医生名称" align="center"> </vxe-column> -->
        <vxe-column field="patId" title="病人ID" width="100">
          <template #default="{ row }">
            <span>{{ row.patId ? row.patId : '' }}</span>
            <span></span>
          </template>
        </vxe-column>
        <vxe-column field="patNa" title="姓名" width="60">
          <template #default="{ row }">
            <span>{{ row.patNa ? row.patNa : '' }}</span>
            <span></span>
          </template>
        </vxe-column>
        <vxe-column field="sexNa" title="性别" width="45">
          <template #default="{ row }">
            <span> {{ row.sexNa }}</span>
            <span></span>
          </template>
        </vxe-column>
        <vxe-column field="medicalRecAge" title="年龄" width="50">
          <template #default="{ row }">
            <span>{{ row.ageStr ? row.ageStr : '' }}</span>
            <span></span>
          </template>
        </vxe-column>
        <vxe-column field="sampleTypeNa" title="样本类型" width="70">
          <template #default="{ row }">
            <span>{{ row.sampleTypeNa ? row.sampleTypeNa : '' }}</span>
          </template>
        </vxe-column>
        <vxe-column field="reqPurpose" title="申请项目" min-width="200">
          <template #default="{ row }">
            <span>{{ row.reqPurpose ? row.reqPurpose : '' }}</span>
            <span></span>
          </template>
        </vxe-column>
        <vxe-column field="reqDoctorNa" title="申请人" width="60">
          <template #default="{ row }">
            <span>{{ row.reqDoctorNa ? row.reqDoctorNa : '' }}</span>
          </template>
        </vxe-column>
        <vxe-column field="reqTime" title="申请时间" width="120">
          <template #default="{ row }">
            <span>{{ row.reqTime ? row.reqTime : '' }}</span>
          </template>
        </vxe-column>
        <vxe-column field="samplingDoctorNa" title="采集人" width="80" v-if="code === '40'">
          <template #default="{ row }">
            <span>{{ row.samplingDoctorNa ? row.samplingDoctorNa : '' }}</span>
          </template>
        </vxe-column>
        <vxe-column field="samplingTime" title="采集时间" min-width="120" v-if="code === '40'">
          <template #default="{ row }">
            <span>{{ row.samplingTime ? row.samplingTime : '' }}</span>
          </template>
        </vxe-column>
        <vxe-column field="signer" title="签收人" width="80" v-if="code === '70'">
          <template #default="{ row }">
            <span>{{ row.signerNa ? row.signerNa : '' }}</span>
          </template>
        </vxe-column>
        <vxe-column field="signTime" title="签收时间" width="120" v-if="code === '70'">
          <template #default="{ row }">
            <span>{{ row.signTime ? row.signTime : '' }}</span>
          </template>
        </vxe-column>
        <!-- <vxe-column field="signer" title="接收人" width="80" v-if="code === 'bbjs'">
                <template #default="{ row }">
                  <span>{{ row.signerNa ? row.signerNa : '' }}</span>
                </template>
              </vxe-column>
              <vxe-column field="signTime" title="接收时间" width="120" v-if="code === 'bbjs'">
                <template #default="{ row }">
                  <span>{{ row.signTime ? row.signTime : '' }}</span>
                </template>
              </vxe-column> -->
        <vxe-column field="signer" title="送达人" width="80" v-if="code === '60'">
          <template #default="{ row }">
            <span>{{ row.signerNa ? row.signerNa : '' }}</span>
          </template>
        </vxe-column>
        <vxe-column field="signTime" title="送达时间" width="120" v-if="code === '60'">
          <template #default="{ row }">
            <span>{{ row.signTime ? row.signTime : '' }}</span>
          </template>
        </vxe-column>
        <vxe-column field="signer" title="送出人" width="80" v-if="code === '50'">
          <template #default="{ row }">
            <span>{{ row.signerNa ? row.signerNa : '' }}</span>
          </template>
        </vxe-column>
        <vxe-column field="signTime" title="送出时间" width="120" v-if="code === '50'">
          <template #default="{ row }">
            <span>{{ row.signTime ? row.signTime : '' }}</span>
          </template>
        </vxe-column>
      </vxe-table>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref, reactive, onMounted, getCurrentInstance } from 'vue';
import { Splitpanes, Pane } from 'splitpanes';
// import MenuList from './MenuList.vue';
import Breadcrumb from '../../../components/Breadcrumb.vue';
import VxePulldownSelection from '../../../components/VxePulldownSelection.vue';
import VxePulldownSelectIconfont from '../../../components/VxePulldownSelectIconfont.vue';
import { VXETable } from 'vxe-table';
import { VxeMessage, VxeNotifyType } from '../../../utils/CommonMessage';
import { AppStore } from '../../../stores/store';
import { funBdsJsResult } from '@/utils/Expression'; //函数公式
let store = AppStore();
let { proxy }: any = getCurrentInstance();
//暴露属性和方法
defineExpose({
  initPage
});

let code = ref('');
// 获取屏幕宽度
let conWidth = ref(document.documentElement.clientWidth);

// 子组件ref名称
let refselectIcon = ref(null);

// 页面标题
let content = ref('不合格记录原因');
// 用户输入关键字
let keywords = ref('');

// 加载中 loading效果状态
let showLoading = ref(false); //刷新

//**判断为空*/
let IsEmpty = (value: any) => {
  if (value === undefined || value === '' || value === null) {
    return true;
  }
  if (JSON.stringify(value) === '{}') {
    return true;
  }
  return false;
};

onMounted(() => {
  code.value = proxy.$route.query.code;
  getRptMainlistByBatchNo();
});

// 表格规则
let formRule = ref({
  name: [
    {
      required: true,
      message: '请输入不合格原因',
      trigger: 'blur'
    }
  ]
});
let batchNo = '';
function initPage(row: any) {
  if (!IsEmpty(row)) {
    batchNo = row.batchNo;
  }
  getRptMainlistByBatchNo();
}
// 模块功能表格数据
let reqMainList: any = reactive([]);

function quietPrint() {
  VXETable.modal.message({ content: '暂无交接单模版', status: 'error' });
}
// 请求表格数据
function getRptMainlistByBatchNo() {
  showLoading.value = true;
  reqMainList.length = 0; //放入数据前清空数组
  proxy.$http
    .get('/lab/delivery/receipt/getRptMainlistByBatchNo', {
      params: { batchNo: batchNo }
    })
    .then((res: any) => {
      if (res.status.code === 200) {
        showLoading.value = false;
        reqMainList.push(...res.data);
        moduleRowClick({ row: reqMainList[0], rowIndex: 0 });
        // VXETable.modal.message({ content: res.status.msg, status: 'success' });
      } else {
        VXETable.modal.message({ content: res.status.msg, status: 'error' });
        return;
      }
    });
  showLoading.value = false;
}

// 当前选中行的下标
let clickIndex = null;
// 点击行
function moduleRowClick({ row, rowIndex }) {
  clickIndex = rowIndex;
  let $Xtable = proxy.$refs.unqualifiedTable;
  $Xtable.setCurrentRow(row);
}
// 点击刷新
function handleSearch() {
  getRptMainlistByBatchNo();
}
let unqualifiedTable = ref();
// 关键字搜索
function search() {
  getRptMainlistByBatchNo();
}

function keyup(e: any) {
  if (e.$event.code == 'Enter') {
    search();
  }
}
</script>
<style lang="scss" scoped>
#FunctionModule {
  height: 100%;
  width: 100%;

  // 左边表格
  .modulTable {
    height: calc(100% - 40px);
    background-color: $base-white;
  }
}
</style>
